<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="/common/commonCss.jsp" />
<jsp:include page="/common/commonJs.jsp" />
<script type="text/javascript" src="${basePath }commonJs/verify.js"></script>
<title>嘉童游乐中心-商品出库</title>
<script type="text/javascript">
	$(document).ready(function() {
		$("#branIdSelect option[value='${branId}']").attr("selected",true);
		refreshSelect();
		$("#fkBranId").val("${branId}");
		initTab();
	});

	function initTab() {
		$("#pkOutstgId").val($("#outstgIdValue").val());
		var form = $("#goodOutForm");
		var pagenbean = new PageBean(form);
		pagenbean.setTableId("goodOutTable");
		pagenbean.setCallback(initTable);
		pagenbean.setFootId("goodOutFoot");
		setPagebeanObj(pagenbean);
		pagenbean.doPage();
	}
	function initTable(data) {
		if (data == null) {
			return;
		}
		var verify = isVerify("${basePath }", "stock:delete3");
		trimJsonArray(data);
		$.each(data, function(ind, obj) {
			var i = ind + 1;
			var date;
			var time = "";
			if(obj.modiTime != null || obj.modiTime != "")
				{
					date= new Date(obj.modiTime);
					time = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate(); 
				}
			var outstgId = obj.pkOutstgId;
			var htm = "<tr>";
			htm += "<td>" + i + "</td>";
			htm += "<td class='lv'><a href='#'onclick = 'toStockDetail(this);' outstgId = '"+outstgId+"'>" + outstgId + "</a></td>";
			htm += "<td>" + obj.fkAttFile + "</td>";
			htm += "<td>" + time + "</td>";
			htm += "<td>" + obj.usrName + "</td>";
			if(verify)
				{
				htm += "<td><input type='button' class='btn_l' value='删除' onclick=\"delOutStock(this);\" outstgId="+obj.pkOutstgId+"></td></tr>";
				}
			else
				{
				htm += "<td></td></tr>";
				}
			$("#goodOutTable").find("tr:eq(" + ind + ")").after(htm);
		});
	}
	
	//跳转到出库清单
	function toStockDetail(obj)
	{
		var outstgId = $(obj).attr("outstgId");
		$("#pkOutstgIdDetail").val(outstgId);
		$("#toDetail").submit();
	}
	
	//出库单删除操作
	function delOutStock(obj) 
	{
		$.messager.confirm('警告', $common_confirm_delete, function(r) {
			if (r) {
				var outstgId = $(obj).attr("outstgId");
				$.ajax({
					url:"${basePath}StockGoodsOut/rollBackForStockOut.shtml",
					data:{"pkOutstgId":outstgId},
					dataType:"text",
					type:"post",
					async:false,
					success:function (result)
					{
						if(result == 1)
						{
							alertInfo($common_delete_success);
							initTab();
						}
						if(result == 0)
						{
							alertError($common_delete_failure);
						}
					},
					error : function(XMLHttpRequest) {
						ajaxError(XMLHttpRequest);
					}
				});	
			}
		});
		
	}
	
	//更换门店
	function branSelectFun() {
		$("#fkBranId").val($("#branIdSelect").val());
	}
</script>

</head>
<body class="bg">
	<div class="content m_auto">
		<div class="content_l mt10">
			<ul>
				<shiro:hasPermission name="StockGoodsIn/toStock_goodsIn.shtml">
					<li><a href="${basePath}StockGoodsIn/toStock_goodsIn.shtml"><i class="nav_icon_b"></i><br>商品入库</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="StockQuery/toStockQuery.shtml">
					<li><a href="${basePath}StockQuery/toStockQuery.shtml"><i class="nav_icon_b"></i><br>库存查询</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="StockGoodsOut/toStockGoodsOut.shtml">
					<li class="content_hover"><a href="${basePath}StockGoodsOut/toStockGoodsOut.shtml"><i class="nav_icon_b"></i><br>商品出库</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="StockTaking/toStockTaking.shtml">
					<li><a href="${basePath}StockTaking/toStockTaking.shtml"><i class="nav_icon_a"></i><br>库存盘点</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="StockCorrect/toStockCorrect.shtml">
					<li><a href="${basePath}StockCorrect/toStockCorrect.shtml"><i class="nav_icon_f"></i><br>库存调整</a></li>
				</shiro:hasPermission>
			</ul>
		</div>
		<div class="content_r mt10">
			<div class="p20">
				<div class="file_single_dl f14 fixed">
					<dl class="fixed" style="overflow: hidden">
						<dd>
							<label>出库单号：</label><input type="text" class="iput_t w200"
								id="outstgIdValue">
						</dd>
						<dd><label>所属门店：</label>
	                		<!----select--->
	                  	 	<div class="uboxstyle">
	                        	<select name="branIdSelect" id="branIdSelect" onchange="branSelectFun();">
	                        		<c:forEach items="${branList}" var="bran">
	                        			<option value="${bran.pkBranId}">${bran.branName}</option>
	                        		</c:forEach>
	                        	</select>
	                   		 </div>
	                   		 <!----select--->
                 		</dd>
						<dd>
							<input type="button" class="btn ml10" value="查询" onclick="initTab()">
							<shiro:hasPermission name="stock:add3">
							<input class="btn ml10" type="button" onclick="javascript:window.location.href='${basePath}StockGoodsOut/toStockAddGoodsOut.shtml'" value="新增出库">
							</shiro:hasPermission>
						</dd>
					</dl>

				</div>
				<form action="${basePath}StockGoodsOut/findscmOutStg.shtml" id="goodOutForm">
					<input type="hidden" name="pageNo" value="1"> 
					<input type="hidden" name="pageSize" value="10"> 
					<input type="hidden" name="pkOutstgId" id="pkOutstgId">
					<input type="hidden" name="fkBranId" id="fkBranId">
				</form>
				
				<form action="${basePath}StockGoodsOut/toStockGoodsOutDetail.shtml" id="toDetail">
					<input type="hidden" name="pkOutstgId" id="pkOutstgIdDetail">
				</form>
				<table class="table" id="goodOutTable">
					<tr>
						<th>序号</th>
                        <th>出库单编号</th>
                        <th>出库单附件</th>
                        <th>出库日期</th>
                        <th>出库操作人</th>
                        <th>操作</th>
					</tr>
				</table>
				<!----翻页----->
				<div class="page fr m10" id="goodOutFoot"></div>
				<!----翻页----->
			</div>
		</div>
	</div>
</body>
</html>